﻿<?xml version="1.0" encoding="UTF-8" ?>
<grammar version="1.0" xml:lang="en-US"
         xmlns="http://www.w3.org/2001/06/grammar"
         tag-format="semantics/1.0" root="Main">

  <rule id="Main">
    <one-of>
      <item> <ruleref uri="#Actions"/> </item>
      <item> Computer <ruleref uri="#Actions"/> </item>
      <item> Computer please <ruleref uri="#Actions"/> </item>
      <item> Please <ruleref uri="#Actions"/> </item>
    </one-of>
  </rule>

  <rule id="Actions" scope="public">
    <one-of>
      <item> <ruleref uri="#MetaCommandsAction"/> </item>
      <item> <ruleref uri="#LightsAction"/> <tag> out.module = rules.LightsAction.module; out.command = rules.LightsAction.command; out.device = rules.LightsAction.device; </tag> </item>
      <!--<item> <ruleref uri="#WeatherAction"/> </item>-->
    </one-of>
  </rule>

  <rule id="DeviceAction" scope="public">
    <one-of>
      <item> on <tag> out.command="DON"; </tag> </item>
      <item> off <tag> out.command="DOF"; </tag> </item>
    </one-of>
  </rule>
  
  <rule id="MetaCommandsAction" scope="public">
    <one-of>
      <item> reload the grammar <tag> out.command = "ReloadGrammar"; out.module = "MetaCommands"; </tag> </item>
      <item> list <item repeat="0-1">the</item> nodes <tag> out.command = "ListNodes"; out.module = "ISYHomeAutomation"; </tag> </item>
    </one-of>
  </rule>
  
  <!-- ############################## ISY HOME AUTOMATION MODULE ############################## -->
  
  <rule id="LightsAction" scope="public">
    <example>(turn) (the) lights in (the) middle office off</example>
    <example>(turn) (the) middle office lights off</example>
    <example>(turn) (the) lights off in (the) middle office</example>
    <example>turn off (the) middle office lights</example>
    <example>middle office lights off</example>
    <tag> out.module = "ISYHomeAutomation"; </tag>
    <one-of>
      <item> <item repeat="0-1">turn</item> <item repeat="0-1">the</item> lights in <item repeat="0-1">the</item> <ruleref uri="#Lights"/> <tag> out.device=rules.Lights.device; </tag> <ruleref uri="#DeviceAction"/> <tag> out.command=rules.DeviceAction.command; </tag> </item>
      <item> <item repeat="0-1">turn</item> <item repeat="0-1">the</item> <ruleref uri="#Lights"/> <tag> out.device=rules.Lights.device; </tag> lights <ruleref uri="#DeviceAction"/> <tag> out.command=rules.DeviceAction.command; </tag> </item>
      <item> <item repeat="0-1">turn</item> <item repeat="0-1">the</item> lights <ruleref uri="#DeviceAction"/> <tag> out.command=rules.DeviceAction.command; </tag> in <item repeat="0-1">the</item> <ruleref uri="#Lights"/> <tag> out.device=rules.Lights.device; </tag></item>
      <item> turn <ruleref uri="#DeviceAction"/> <tag> out.command=rules.DeviceAction.command; </tag> the <ruleref uri="#Lights"/> <tag> out.device=rules.Lights.device; </tag> lights</item>
      <item> <ruleref uri="#Lights"/> <tag> out.device=rules.Lights.device; </tag> lights <ruleref uri="#DeviceAction"/> <tag> out.command=rules.DeviceAction.command; </tag> </item>
    </one-of>
  </rule>

  <rule id="Lights" scope="public">
    <one-of>
      <item> <ruleref uri="#LightsCornerOffice"/> <tag> out.device="23 C1 B5 1"; </tag> </item>
      <item> <ruleref uri="#LightsMiddleOffice"/> <tag> out.device="22 F2 FF 1"; </tag> </item>
      <item> <ruleref uri="#LightsHallway"/> <tag> out.device="22 A5 52 1"; </tag> </item>
      <item> <ruleref uri="#LightsBedroom"/> <tag> out.device="22 F8 9E 1"; </tag> </item>
      <item> <ruleref uri="#LightsDining"/> <tag> out.device="23 B0 64 1"; </tag> </item>
      <item> <ruleref uri="#LightsKitchen"/> <tag> out.device="22 AA 35 1"; </tag> </item>
      <item> <ruleref uri="#LightsEntrance"/> <tag> out.device="21 7 A8 1"; </tag> </item>
      <item> <ruleref uri="#LightsGarage"/> <tag> out.device="FF 0B 02 1"; </tag> </item>
      <item> <ruleref uri="#LightsFront"/> <tag> out.device="1F DA 7B 1"; </tag> </item>
      <item> <ruleref uri="#LightsBack"/> <tag> out.device="FF 01 03 1"; </tag> </item>
    </one-of>
  </rule>
  
  <rule id="LightsCornerOffice" scope="public">
    <one-of>
      <item> corner <item repeat="0-1">office</item> </item>
    </one-of>
  </rule>

  <rule id="LightsMiddleOffice" scope="public">
    <one-of>
      <item> middle <item repeat="0-1">office</item> </item>
    </one-of>
  </rule>

  <rule id="LightsHallway" scope="public">
    <one-of>
      <item><item repeat="0-1">upper</item> hallway</item>
    </one-of>
  </rule>

  <rule id="LightsBedroom" scope="public">
    <one-of>
      <item> bedroom </item>
    </one-of>
  </rule>

  <rule id="LightsDining" scope="public">
    <one-of>
      <item> dining <item repeat="0-1">table</item> </item>
    </one-of>
  </rule>

  <rule id="LightsKitchen" scope="public">
    <one-of>
      <item>kitchen <item repeat="0-1">table</item></item>
    </one-of>
  </rule>

  <rule id="LightsEntrance" scope="public">
    <one-of>
      <item>entrance</item>
    </one-of>
  </rule>

  <rule id="LightsGarage" scope="public">
    <one-of>
      <item>garage</item>
    </one-of>
  </rule>

  <rule id="LightsFront" scope="public">
    <one-of>
      <item>front <item repeat="0-1">porch</item></item>
      <item>porch</item>
    </one-of>
  </rule>

  <rule id="LightsBack" scope="public">
    <one-of>
      <item>back</item>
      <item>backyard</item>
    </one-of>
  </rule>

  <!-- ############################## WEATHER MODULE ############################## -->

  <!--
  
  Dictation does not work very well, need to figure out a better way (list of cities? only current location?)
  
  <rule id="WeatherAction" scope="public">
    <one-of>
      <item>How's the weather like in <ruleref uri="grammar:dictation" type="application/srgs+xml"/> <tag>out.SpokenText=rules.latest();</tag></item>
    </one-of>
  </rule>
  -->
  
</grammar>